module.exports = (sequelize, DataTypes) => {
  const member = sequelize.define('member', {
    memberId: {
      type: DataTypes.STRING(50),
      primaryKey: true
    }, // 账号id不可重复
    name: {
      type: DataTypes.STRING(50),
      allowNull: false
    }, // 昵称可重复
    // email: DataTypes.STRING(50),
    phone: {
      type: DataTypes.STRING(11),
      allowNull: false
    },
    recommendId: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    settleId: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    position: DataTypes.ENUM('left', 'right'),
    password: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    credential: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    grade: {
      type: DataTypes.STRING(50),
      defaultValue: 'D1'
    },
    originGene: {
      type: DataTypes.DOUBLE,
      defaultValue: 0
    },
    flowGene: {
      type: DataTypes.DOUBLE,
      defaultValue: 0
    },
    elec: {
      type: DataTypes.DOUBLE,
      defaultValue: 0
    },
    resell: DataTypes.DOUBLE,
    creditCard: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    creditImg: {
      type: DataTypes.STRING,
      allowNull: false
    },
    token: DataTypes.STRING,
    device: DataTypes.STRING,
    ip: DataTypes.STRING(50),
    loginTime: DataTypes.DATE,
    outdateTime: DataTypes.DATE,
    disable: {
      type: DataTypes.BOOLEAN,
      defaultValue: false
    }
  })

  member.associate = (models) => {
    member.hasMany(models.cart, {
      foreignKey: 'memberId',
      sourceKey: 'memberId',
      as: 'carts'
    })
    member.hasMany(models.order, {
      foreignKey: 'memberId',
      sourceKey: 'memberId',
      as: 'orders'
    })
  }
  return member
}
